import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hc_ui/config/hc_customer_config.dart';
import 'package:hc_ui/config/hc_default_theme_config.dart';
import 'package:hc_ui/theme/hc_base_theme.dart';

import 'hc_common_theme.dart';

class HcTitleTheme extends HcBaseTheme<HcTitleTheme> {
  //标题的文字样式
  TextStyle? _titleStyle;

  //副标题样式
  TextStyle? _subtitleStyle;

  //副标题堆叠样式
  TextStyle? _stackSubtitleStyle;

  //标题左外间距
  EdgeInsets? _titleMargin;

  //副标题左外边距
  EdgeInsets? _subtitleMargin;

  //右侧组件左外边距
  EdgeInsets? _trailingMargin;

  //整个组件的内边距
  EdgeInsets? _widgetPadding;

  //整个组件的外边距
  EdgeInsets? _margin;

  //对齐方式
  MainAxisAlignment? _alignment;

  //右侧图标颜色
  Color? _trailingColor;

  //左侧图标大小
  double? _leadingSize;

  //右侧图标大小
  double? _trailingSize;

  //下划线的透明度
  double? _underlineOpacity;

  //点的透明度
  double? _dotOpacity;

  //堆叠的副标题的透明度
  double? _stackSubtitleOpacity;
  double? _underlineStartIndent;
  double? _underlineEndIndent;

  //背景颜色
  Color? _backgroundColor;

  //左侧图标颜色
  Color? _leadingColor;

  //下划线颜色
  Color? _underlineColor;

  //点的颜色
  Color? _dotColor;

  HcTitleTheme({
    TextStyle? titleStyle,
    TextStyle? subtitleStyle,
    TextStyle? stackSubtitleStyle,
    EdgeInsets? titleMargin,
    EdgeInsets? subtitleMargin,
    EdgeInsets? widgetPadding,
    EdgeInsets? trailingMargin,
    EdgeInsets? margin,
    MainAxisAlignment? alignment,
    Color? leadingColor,
    Color? trailingColor,
    Color? backgroundColor,
    Color? underlineColor,
    Color? dotColor,
    double? leadingSize,
    double? trailingSize,
    double? underlineOpacity,
    double? stackSubtitleOpacity,
    double? underlineStartIndent,
    double? underlineEndIndent,
    double? dotOpacity,
  })  : _titleStyle = titleStyle,
        _titleMargin = titleMargin,
        _widgetPadding = widgetPadding,
        _subtitleMargin = subtitleMargin,
        _trailingMargin = trailingMargin,
        _alignment = alignment,
        _backgroundColor = backgroundColor,
        _underlineColor = underlineColor,
        _dotColor = dotColor,
        _leadingSize = leadingSize,
        _trailingSize = trailingSize,
        _underlineOpacity = underlineOpacity,
        _stackSubtitleOpacity = stackSubtitleOpacity,
        _underlineStartIndent = underlineStartIndent,
        _underlineEndIndent = underlineEndIndent,
        _dotOpacity = dotOpacity,
        _leadingColor = leadingColor,
        _trailingColor = trailingColor,
        _margin = margin,
        _subtitleStyle = subtitleStyle,
        _stackSubtitleStyle = stackSubtitleStyle;

  @override
  HcTitleTheme merge(value) {
    if (value == null) return this;
    return copyWith(
        titleStyle: titleStyle.merge(value._titleStyle),
        subtitleStyle: subtitleStyle.merge(value._subtitleStyle),
        stackSubtitleStyle: stackSubtitleStyle.merge(value._stackSubtitleStyle),
        widgetPadding: value.widgetPadding,
        titleMargin: value._titleMargin,
        subtitleMargin: value._subtitleMargin,
        trailingMargin: value._trailingMargin,
        margin: value._margin,
        trailingSize: value._trailingSize,
        leadingSize: value._leadingSize,
        underlineOpacity: value._underlineOpacity,
        stackSubtitleOpacity: value._stackSubtitleOpacity,
        underlineStartIndent: value._underlineStartIndent,
        underlineEndIndent: value._underlineEndIndent,
        dotOpacity: value._dotOpacity,
        trailingColor: value._trailingColor,
        leadingColor: value._leadingColor,
        backgroundColor: value._backgroundColor,
        underlineColor: value._underlineColor,
        dotColor: value._dotColor,
        alignment: value._alignment);
  }

  HcTitleTheme copyWith({
    TextStyle? titleStyle,
    TextStyle? subtitleStyle,
    TextStyle? stackSubtitleStyle,
    EdgeInsets? titleMargin,
    EdgeInsets? subtitleMargin,
    EdgeInsets? widgetPadding,
    EdgeInsets? trailingMargin,
    EdgeInsets? margin,
    MainAxisAlignment? alignment,
    Color? leadingColor,
    Color? trailingColor,
    double? leadingSize,
    double? trailingSize,
    double? underlineOpacity,
    double? stackSubtitleOpacity,
    double? underlineStartIndent,
    double? underlineEndIndent,
    double? dotOpacity,
    Color? backgroundColor,
    Color? underlineColor,
    Color? dotColor,
  }) {
    return HcTitleTheme(
      titleStyle: titleStyle ?? _titleStyle,
      subtitleStyle: subtitleStyle ?? _subtitleStyle,
      stackSubtitleStyle: stackSubtitleStyle ?? _stackSubtitleStyle,
      titleMargin: titleMargin ?? _titleMargin,
      subtitleMargin: subtitleMargin ?? _subtitleMargin,
      trailingMargin: trailingMargin ?? _trailingMargin,
      widgetPadding: widgetPadding ?? _widgetPadding,
      trailingColor: trailingColor ?? _trailingColor,
      leadingColor: leadingColor ?? _leadingColor,
      leadingSize: leadingSize ?? _leadingSize,
      trailingSize: trailingSize ?? _trailingSize,
      underlineOpacity: underlineOpacity ?? _underlineOpacity,
      stackSubtitleOpacity: stackSubtitleOpacity ?? _stackSubtitleOpacity,
      underlineStartIndent: underlineStartIndent ?? _underlineStartIndent,
      underlineEndIndent: underlineEndIndent ?? _underlineEndIndent,
      dotOpacity: dotOpacity ?? _dotOpacity,
      margin: margin ?? _margin,
      backgroundColor: backgroundColor ?? _backgroundColor,
      underlineColor: underlineColor ?? _underlineColor,
      dotColor: dotColor ?? _dotColor,
      alignment: alignment ?? _alignment,
    );
  }

  @override
  initTheme({HcCommonTheme? tempTheme}) {
    super.initTheme(tempTheme: tempTheme);
    HcTitleTheme userTheme = HcCustomerConfig().allTheme.titleTheme;
    _titleStyle ??= TextStyle(
        fontSize: commonTheme.fontSizeTitle,
        color: commonTheme.textTitleColor,
        height: commonTheme.fontHeightLg,
        fontWeight: FontWeight.w400);
    _subtitleStyle ??= TextStyle(
        fontSize: commonTheme.fontSizeHint,
        color: commonTheme.textHintColor,
        height: commonTheme.fontHeightLg,
        fontWeight: FontWeight.w400);
    _stackSubtitleStyle ??= TextStyle(
        fontSize: commonTheme.fontSizeTitle,
        color: commonTheme.primaryColor,
        height: commonTheme.fontHeightMd,
        fontWeight: FontWeight.w400);
    _titleMargin ??= EdgeInsets.only(left: commonTheme.vSpacingSm);
    _subtitleMargin ??= EdgeInsets.only(left: commonTheme.vSpacingSm);
    _trailingMargin ??= EdgeInsets.only(left: commonTheme.vSpacingSm);
    _widgetPadding ??= EdgeInsets.only(
        top: commonTheme.vSpacingPage,
        bottom: commonTheme.vSpacingPage,
        left: commonTheme.hSpacingXs);
    _margin ??= EdgeInsets.symmetric(vertical: commonTheme.lineBase);
    _alignment ??= userTheme.alignment;
    _backgroundColor ??= userTheme.backgroundColor;
    _underlineColor ??= commonTheme.primaryColor;
    _dotColor ??= commonTheme.primaryColor;
    _leadingColor ??= commonTheme.textTitleColor;
    _trailingColor ??= commonTheme.textDisableColor;
    _leadingSize ??= commonTheme.iconSizeSm;
    _trailingSize ??= commonTheme.iconSizeXxs;
    _underlineOpacity ??= userTheme.underlineOpacity;
    _stackSubtitleOpacity ??= userTheme.stackSubtitleOpacity;
    _underlineStartIndent ??= userTheme.underlineStartIndent;
    _underlineEndIndent ??= userTheme.underlineEndIndent;
    _dotOpacity ??= userTheme.dotOpacity;
  }

  TextStyle get titleStyle =>
      _titleStyle ?? HcDefaultThemeConfig.defaultTitleTheme.titleStyle;

  TextStyle get subtitleStyle =>
      _subtitleStyle ?? HcDefaultThemeConfig.defaultTitleTheme.subtitleStyle;

  TextStyle get stackSubtitleStyle =>
      _stackSubtitleStyle ??
      HcDefaultThemeConfig.defaultTitleTheme.stackSubtitleStyle;

  MainAxisAlignment get alignment =>
      _alignment ?? HcDefaultThemeConfig.defaultTitleTheme.alignment;

  Color get backgroundColor =>
      _backgroundColor ??
      HcDefaultThemeConfig.defaultTitleTheme.backgroundColor;

  Color get underlineColor =>
      _underlineColor ?? HcDefaultThemeConfig.defaultTitleTheme.underlineColor;

  Color get dotColor =>
      _dotColor ?? HcDefaultThemeConfig.defaultTitleTheme.dotColor;

  double get trailingSize =>
      _trailingSize ?? HcDefaultThemeConfig.defaultTitleTheme.trailingSize;

  double get leadingSize =>
      _leadingSize ?? HcDefaultThemeConfig.defaultTitleTheme.leadingSize;

  Color get trailingColor =>
      _trailingColor ?? HcDefaultThemeConfig.defaultTitleTheme.trailingColor;

  Color get leadingColor =>
      _leadingColor ?? HcDefaultThemeConfig.defaultTitleTheme.leadingColor;

  EdgeInsets get margin =>
      _margin ?? HcDefaultThemeConfig.defaultTitleTheme.margin;

  EdgeInsets get widgetPadding =>
      _widgetPadding ?? HcDefaultThemeConfig.defaultTitleTheme.widgetPadding;

  EdgeInsets get subtitleMargin =>
      _subtitleMargin ?? HcDefaultThemeConfig.defaultTitleTheme.subtitleMargin;

  EdgeInsets get trailingMargin =>
      _trailingMargin ?? HcDefaultThemeConfig.defaultTitleTheme.trailingMargin;

  EdgeInsets get titleMargin =>
      _titleMargin ?? HcDefaultThemeConfig.defaultTitleTheme.titleMargin;

  double get stackSubtitleOpacity =>
      _stackSubtitleOpacity ??
      HcDefaultThemeConfig.defaultTitleTheme.stackSubtitleOpacity;

  double get underlineStartIndent =>
      _underlineStartIndent ??
      HcDefaultThemeConfig.defaultTitleTheme.underlineStartIndent;

  double get underlineEndIndent =>
      _underlineEndIndent ??
      HcDefaultThemeConfig.defaultTitleTheme.underlineEndIndent;

  double get dotOpacity =>
      _dotOpacity ?? HcDefaultThemeConfig.defaultTitleTheme.dotOpacity;

  double get underlineOpacity =>
      _underlineOpacity ??
      HcDefaultThemeConfig.defaultTitleTheme.underlineOpacity;
}
